package part5;

/**
 * @author wcj
 * @Date 2021/5/13 16:34
 * @Version 1.0
 */
public class Part510 {
    public static void main(String[] args) {
        System.out.println("Create new Cupboard");
        new Cupboard();
        System.out.println("Create new Cupboard");
        new Cupboard();
        table.f2(1);
        cupboard.f3(1);
    }

    /**
     * 静态代码块
     */
    static {
        int i = 10;
        String j = "lll";
    }

    static Table table = new Table();
    static Cupboard cupboard = new Cupboard();
}

/**
 * 静态成员的初始化只有在类初始化的时候或者调用类的静态成员时执行一次，之后不再执行
 * 非静态成员，每当类进行初始化的时候都会重新进行初始化
 */
class Bowl {
    public Bowl(int marker) {
        System.out.println("Bowl marker:" + marker);
    }

    public void f1(int marker) {
        System.out.println("f1 marker:" + marker);
    }
}

class Table {
    static Bowl bowl = new Bowl(1);

    public Table() {
        System.out.println("Table");
        bowl2.f1(1);
    }

    public void f2(int marker) {
        System.out.println("f2 marker:" + marker);
    }

    static Bowl bowl2 = new Bowl(2);
}

class Cupboard {
    Bowl bowl3 = new Bowl(3);
    static Bowl bowl4 = new Bowl(4);

    public Cupboard() {
        System.out.println("Cupboard");
        bowl4.f1(2);
    }

    public void f3(int marker) {
        System.out.println("f3 marker:" + marker);
    }

    static Bowl bowl5 = new Bowl(5);
}
